/*
DataWrapper.m - Copyright (c) 1992 NeXT Computer, Inc.

You may freely copy, distribute and reuse the code in this example.
NeXT Computer, Inc. disclaims any warranty of any kind, expressed or implied, 
as to its fitness for any particular use.
*/

#import <strings.h>
#import <appkit/appkit.h>
#import "DataWrapper.h"

@implementation	DataWrapper

- (const char *)key
{
    return key;
}

- setKey:(const char *)aKey
{
    char *tmp = (char *)0;

    if (aKey) {
	tmp = (char *) malloc(1 + strlen(aKey));
	if (tmp == NULL) return nil;
	strcpy(tmp, aKey);
    }

    if (key) free(key);
    key = tmp;
    return self;
}

- (int)value
{
    return value;
}

- setValue:(int) anInt
{
    value = anInt;
    return self;
}

- read:(NXTypedStream *)stream
{
    [super read:stream];
    NXReadTypes(stream, "*i", &key, &value);
    return self;
}

- write:(NXTypedStream *)stream
{
    [super write:stream];
    NXWriteTypes(stream, "*i", &key, &value);
    return self;
}

- free
{
    if (key) free(key);
    return [super free];
}

@end

